package com.study.design.pattern.pattern.behavioral.memento;

import java.util.Stack;

/**
 * @Author: gongsl
 * @Date: 2025-03-24 21:57
 * @description: 负责人类：管理备忘录
 */
public class Caretaker {
    private final Stack<Memento> history = new Stack<>();

    public void saveState(TextEditor editor) {
        history.push(editor.save());
    }

    public void undo(TextEditor editor) {
        if (!history.isEmpty()) {
            editor.restore(history.pop());
        }
    }
}
